package com.aspire.core.gw;

import javax.servlet.http.HttpServletRequest;

import com.aspirecn.core.ShareCommon;
import com.aspirecn.core.datacache.IPGatewayCache;
import com.aspirecn.core.object.IP;
import com.aspirecn.core.commons.IPUtils;

public class GatewayCenter {

	// 网关常量
	public static final int CMWAP_GATEWAY = IP.CMWAP_GATEWAY;
	public static final int CMNET_GATEWAY = IP.CMNET_GATEWAY;
	public static final int WIFI_GATEWAY = IP.WIFI_GATEWAY;

	private IPGatewayCache ipGatewayCache = ShareCommon.getInstance().getIPGatewayCache();

	public void load() {
		//保留为兼容
	}

	public void reload() {
		load();
	}

	/**
	 * 
	 * @param ip
	 * @return
	 */
	public int getGateWay(String ip) {
		
		IP ipObject = ipGatewayCache.search(ip);
		if( ipObject != null )
		{
			return ipObject.getGateway();
		}
		else
		{
			return IP.WIFI_GATEWAY;
		}		
	}

	/**
	 * 
	 * @param request
	 * @return
	 */
	public int getGateWay(HttpServletRequest request) {

		String ip = IPUtils.getIP(request);
		return this.getGateWay(ip);
	}

	/**
	 * 
	 * @param request
	 * @return
	 */
	public String getIP(HttpServletRequest request) {
		return IPUtils.getIP(request);
	}
	
	
	public static void main( String[] args )
	{
		GatewayCenter gatewayCenter = new GatewayCenter();
		System.out.println( gatewayCenter.getGateWay("218.206.69.13") );
	}
}